package com.bosssoft.ct.springcloud.service.impl;

import com.bosssoft.ct.springcloud.service.HystrixTestService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * Hystrix测试业务实现接口
 *
 * @author ChenTong
 * @version 1.0
 * @date 2020/6/22 21:29
 * @copyright
 * @modified
 * @see
 * @since
 **/
@Service
@Slf4j
public class HystrixTestServiceImpl implements HystrixTestService {
    @Override
    public String adminOK() {
        log.info("线程池："+Thread.currentThread().getName()+"ok");

        return Thread.currentThread().getName()+" hystrix通过";
    }

    @Override
    public String adminTimeout() {
        int timeNum = new Random().nextInt(10)+1;
        log.info("timeout {}",timeNum);
        try {
            TimeUnit.SECONDS.sleep(timeNum);
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return "Thread Pool: "+Thread.currentThread().getName()+" paymentInfo_ERROR "+" 耗时："+timeNum;
    }

    @Override
    public String adminError() {
        //int errorExp = 10/0; 测试报错
        return "hystrix error";
    }
}
